package cn.stylefeng.guns.modular.basic.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.basic.entity.BasicLineIne;
import cn.stylefeng.guns.modular.basic.mapper.BasicLineIneMapper;
import cn.stylefeng.guns.modular.basic.model.params.BasicLineIneParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicLineIneResult;
import  cn.stylefeng.guns.modular.basic.service.BasicLineIneService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 收入报价 服务实现类
 * </p>
 *
 * @author wzh
 * @since 2024-01-15
 */
@Service
public class BasicLineIneServiceImpl extends ServiceImpl<BasicLineIneMapper, BasicLineIne> implements BasicLineIneService {

    @Override
    public void add(BasicLineIneParam param){
        BasicLineIne entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BasicLineIneParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BasicLineIneParam param){
        BasicLineIne oldEntity = getOldEntity(param);
        BasicLineIne newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BasicLineIneResult findBySpec(BasicLineIneParam param){
        return null;
    }

    @Override
    public List<BasicLineIneResult> findListBySpec(BasicLineIneParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BasicLineIneParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BasicLineIneParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BasicLineIne getOldEntity(BasicLineIneParam param) {
        return this.getById(getKey(param));
    }

    private BasicLineIne getEntity(BasicLineIneParam param) {
        BasicLineIne entity = new BasicLineIne();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
